package com.qf.erpb.product.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qf.erpb.core.vo.PageVO;
import com.qf.erpb.product.entity.XgProduct2;
import com.qf.erpb.product.dao.XgProductMapper;
import com.qf.erpb.product.param.ProductParam;
import com.qf.erpb.product.service.XgProductService;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
* @author DELL
* @description 针对表【xg_product】的数据库操作Service实现
* @createDate 2023-12-18 17:50:13
*/
@Service
public class XgProductServiceImpl extends ServiceImpl<XgProductMapper, XgProduct2>
    implements XgProductService {

    @Resource
    private XgProductMapper xgProductMapper;
    @Override
    public PageVO<XgProduct2> pageProduct(ProductParam productParam) {
        Page<XgProduct2> page = new Page<>(productParam.getPageNum(),productParam.getPageSize());

        QueryWrapper<XgProduct2> wrapper = new QueryWrapper<XgProduct2>();
        if (StringUtils.hasLength(productParam.getProductId())){
            wrapper.like("product_id",productParam.getProductId());
        }
        if (StringUtils.hasLength(productParam.getProductName())){
            wrapper.like("product_name",productParam.getProductName());
        }

//        if (productParam.getPrice() != null) {
//            wrapper.eq("Price", productParam.getPrice());
//        }
//        价格范围查询
        if (productParam.getPriceMin() != null && productParam.getPriceMax() != null) {
            wrapper.between("Price", productParam.getPriceMin(), productParam.getPriceMax());
        }

        page = xgProductMapper.selectPage(page,wrapper);

        PageVO<XgProduct2> pageVO = new PageVO<>();
        pageVO.setTotal(page.getTotal());
        pageVO.setDataList(page.getRecords());

        return pageVO;
    }

    @Override
    public int saveBatch(ArrayList<XgProduct2> list) {

        return xgProductMapper.saveBatch(list);
    }

    @Override
    public List<Map<String, Object>> findSex4Charts() {
        return xgProductMapper.findSex4Charts();
    }

    @Override
    public List<Map<String, Object>> findSex4Charts2() {
        return xgProductMapper.findSex4Charts2();
    }
}




